package com.zhuozhou.jdyc.main.settlement.adapter;

import android.content.Context;

import com.baidu.mapapi.model.LatLng;
import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.base.BaseRecyclerViewAdapter;
import com.zhuozhou.jdyc.base.BaseViewHolder;
import com.zhuozhou.jdyc.databinding.AdapterVerificationBinding;
import com.zhuozhou.jdyc.main.settlement.bean.VerificationBean;
import com.zhuozhou.jdyc.util.apiUtil.NumberUtils;
import com.zhuozhou.jdyc.util.apiUtil.StringUtil;
import com.zhuozhou.jdyc.wight.dialog.MapDialog;
import com.zhuozhou.jdyc.wight.recyclerview.MyLayoutManager;

/**
 * Create by CherishTang on 2020/3/27 0027
 * describe:首页菜单adapter
 */
public class VerificationAdapter extends BaseRecyclerViewAdapter<VerificationBean.ListBeanX, AdapterVerificationBinding> {

    public VerificationAdapter(Context context) {
        super(context);
    }

    public OnItemSetMoneyListener mOnItemSetMoneyListener;

    @Override
    protected int getLayoutId() {
        return R.layout.adapter_verification;
    }

    @Override
    public void onBindHolder(BaseViewHolder<AdapterVerificationBinding> holder, int pos) {
        holder.getBinding().setBean(mList.get(pos));
        holder.getBinding().setPrice("￥" + NumberUtils.decimalFormat(mList.get(pos).getPrice() == null ? "0" : mList.get(pos).getPrice())
                + (mList.get(pos).getList().get(0).getType() == 1 ? "" : mList.get(pos).getList().get(0).getType() == 2 ? ("+" + mList.get(pos).getIntegral() + "积分") :
                ("+" + mList.get(pos).getIntegral() + "易货积分")));
        holder.getBinding().tvSee.setOnClickListener(v -> {
            if (mOnItemSetMoneyListener != null)
                mOnItemSetMoneyListener.onItemSetMoney(mList.get(pos).getQr(), mList.get(pos).getMy_out_trade_no());
        });
        VerificationShopAdapter verificationShopAdapter = new VerificationShopAdapter(mContext);
        verificationShopAdapter.setList(mList.get(pos).getList());
        holder.getBinding().mRecyclerViewShop.setAdapter(verificationShopAdapter);
        holder.getBinding().mRecyclerViewShop.setLayoutManager(new MyLayoutManager(mContext));

        holder.getBinding().tvLocation.setOnClickListener(v -> {
            if (StringUtil.isNotEmpty(mList.get(pos).getX()) && StringUtil.isNotEmpty(mList.get(pos).getY()))
                new MapDialog(mContext)
                        .setLocation(new LatLng(Double.parseDouble(mList.get(pos).getX()), Double.parseDouble(mList.get(pos).getY())))
                        .builder()
                        .show();
        });
    }

    public void setOnItemSetMoneyListener(OnItemSetMoneyListener l) {
        mOnItemSetMoneyListener = l;
    }

    public interface OnItemSetMoneyListener {
        void onItemSetMoney(String str, String id);
    }


}
